import { UITransform, v3 } from "cc";
import { BaseView } from "../../../cfw/mvc/BaseView";
import { DIR, FACE_DIR } from "../../../cfw/tools/Define";
import { EVector3, ESize } from "../../../engine/Math";
import { IEnvironment } from "../../env/IEnvironment";
import { BattleObjectModel } from "../model/BattleObjectModel";
import { BaseController } from "../../../cfw/mvc/BaseController";
export class BattleObjectView<C extends BaseController = any, M extends BattleObjectModel = any, E extends IEnvironment = any> extends BaseView<C, M, E> {

    //朝向
    protected faceDir: DIR = DIR.RIGHT;

    protected moveDir: DIR = DIR.RIGHT;

    protected _size: ESize = new ESize()//v2()

    protected transform: UITransform;

    protected speed: EVector3 = v3()

    onLoad(): void {
        super.onLoad();
        this.transform = this.node.getComponent(UITransform)
    }

    getSpeedX(): number {
        return this.speed.x;
    }

    getX(): number {
        return this.node.position.x;
    }

    setSpeedX(x: number): void {
        this.speed.x = x;
    }

    jump(h: number): void {

    }

    getY(): number {
        return this.node.position.y;
    }

    init?(): void {

    }
    // protected temp: EVector3 = new EVector3()
    // setPosition(pos: EVector3): void {
    //     this.temp.x = pos.x;
    //     this.temp.y = pos.y;
    //     this.temp.z = pos.z;
    //     this.node.position = this.temp;
    // }

    getPosition(): EVector3 {
        return this.node.position
    }


    getParent(): any {
        return this.node.parent;
    }

    convertToWorldSpaceAR(v1: EVector3, v2: EVector3): EVector3 {
        return this.transform.convertToWorldSpaceAR(v1, v2)
    }

    convertToNodeSpaceAR(v1: EVector3, v2: EVector3): EVector3 {
        return this.transform.convertToNodeSpaceAR(v1, v2)
    }


    getSize(): ESize {
        let transform = this.node.parent.getComponent(UITransform);
        this._size.width = transform.width;
        this._size.height = transform.height;
        return this._size;
    }

    addChild(node: any, index: number): void {
        this.node.addChild(node)
    }



    getFaceDir(): DIR {
        return this.faceDir
    }

    getInitFaceDir() {
        return DIR.LEFT
    }

    setFaceDir(d: DIR) {
        this.faceDir = d;
        let list = FACE_DIR[this.getInitFaceDir()]
        let num = list[this.faceDir]
        this.scaleX = num;
    }


    getOppsiteDir() {
        if (this.faceDir == DIR.LEFT) {
            return DIR.RIGHT
        } else {
            return DIR.LEFT;
        }
    }


    setMoveDir(dir: DIR, isSame: boolean) {
        this.moveDir = dir;
        if (isSame) {
            this.setFaceDir(this.moveDir)
        }
    }

    getMoveDir() {
        return this.moveDir;
    }

    getDisplayLayer?(): number {
        return 1;
    }
    getKey() {
        return this.model.getKey()
    }
    setKey(key: any): void {
        this.model.setKey(key)
    }

    isDead() {
        return false;
    }

    getType() {
        return 0;
    }

}